<?php

$get_id=$_POST['id'];
$get_id_form=$_POST['form'];
$form_name=$_POST['nomform'];
$user_name=$_POST['nom_user'];


$db = db::getInstance();
$id_reference = new UserDataModel();
$filter = array(new DFC(UserDataModel::FIELD_USER_ID, $get_id, DFC::EXACT),
        (new DFC(UserDataModel::FIELD_FORM_ID, $get_id_form, DFC::EXACT)));
$id_reference = UserDataModel::findByFilter($db, $filter);

foreach ($id_reference as $x)

{
    $id=$x->getIdRef();
}
//extraction

$id_reference_values=new UserDataRefModel();
$filter = array(new DFC(UserDataRefModel::FIELD_ID_REF, $id, DFC::EXACT));
$data=  UserDataRefModel::findByFilter($db, $filter);


$nom_file = $user_name.'xxx'.$form_name.".txt";
$f = fopen('enregistrements/'.$nom_file, "wb");
fputs($f,'FORMULAIRE :'.$form_name);
fwrite($f,"\r\n"); 
fputs($f,'AUTEUR :'.$user_name);
fwrite($f,"\r\n"); 
fwrite($f,"\r\n"); 
fwrite($f,"\r\n"); 

foreach ($data as $x)
{
fputs($f, '| '.$x->getKey().' : '.$x->getValue() );
fwrite($f,"\r\n");           
}
fclose($f);

exec('enregistrements/'.$nom_file);
?>

